package com.powernode.controller;


import com.powernode.service.impl.BookServiceImpl;
import lombok.Data;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.powernode.pojo.Book;
import java.util.List;

/**
 * @author 繁寂
 * @version 1.0
 * @since 1.0
 */
@CrossOrigin
@RestController
@RequestMapping("/book")
public class BookController {

    @Autowired
    private BookServiceImpl bookServiceImpl;

    @GetMapping("/All")
    public List<Book> getBookAllList(){
        return bookServiceImpl.selectBookAll();
    }


    @GetMapping("/select/{name}")
    @ResponseBody
    public List<Book> getBook(@Param("name") String name){
        return bookServiceImpl.selectBook(name);
    }


    @PostMapping("/addBook")
    public String  addBook(@RequestBody Book book){
        int count = bookServiceImpl.insertBook(book);
        if(count == 1){
            return  "添加成功";
        }
            return "添加失败";
    }

    @RequestMapping("/update")
    public String  updateBook(@RequestBody Book book){
        int count = bookServiceImpl.updateBook(book);
        if(count == 1){
            return  "更改成功";
        }
            return "更改失败";
    }

    @PostMapping ("/remove")
    public String removeBook(@RequestBody Book book){
        int count = bookServiceImpl.deleteBook(book);
        if(count == 1){
            return  "删除成功";
        }
            return "删除失败";
    }
}
